<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Hard
  </div>
  <div>
   <h1 class="question_title">
    446. Arithmetic Slices II - Subsequence
   </h1>
   <p>
    A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.
   </p>
   <p>
    For example, these are arithmetic sequences:
   </p>
   <pre>1, 3, 5, 7, 9
7, 7, 7, 7
3, -1, -5, -9</pre>
   <p>
    The following sequence is not arithmetic.
   </p>
   <pre>1, 1, 2, 5, 7</pre>
   <br>
   <p>
    A zero-indexed array A consisting of N numbers is given. A
    <b>
     subsequence
    </b>
    slice of that array is any sequence of integers (P
    <sub>
     0
    </sub>
    , P
    <sub>
     1
    </sub>
    , ..., P
    <sub>
     k
    </sub>
    ) such that 0 &le; P
    <sub>
     0
    </sub>
    &lt; P
    <sub>
     1
    </sub>
    &lt; ... &lt; P
    <sub>
     k
    </sub>
    &lt; N.
   </p>
   <p>
    A
    <b>
     subsequence
    </b>
    slice (P
    <sub>
     0
    </sub>
    , P
    <sub>
     1
    </sub>
    , ..., P
    <sub>
     k
    </sub>
    ) of array A is called arithmetic if the sequence A[P
    <sub>
     0
    </sub>
    ], A[P
    <sub>
     1
    </sub>
    ], ..., A[P
    <sub>
     k-1
    </sub>
    ], A[P
    <sub>
     k
    </sub>
    ] is arithmetic. In particular, this means that k &ge; 2.
   </p>
   <p>
    The function should return the number of arithmetic subsequence slices in the array A.
   </p>
   <p>
    The input contains N integers. Every integer is in the range of -2
    <sup>
     31
    </sup>
    and 2
    <sup>
     31
    </sup>
    -1 and 0 &le; N &le; 1000. The output is guaranteed to be less than 2
    <sup>
     31
    </sup>
    -1.
   </p>
   <br>
   <p>
    <b>
     Example:
    </b>
   </p>
   <pre>
<b>Input:</b> [2, 4, 6, 8, 10]

<b>Output:</b> 7

<b>Explanation:</b>
All arithmetic subsequence slices are:
[2,4,6]
[4,6,8]
[6,8,10]
[2,4,6,8]
[4,6,8,10]
[2,4,6,8,10]
[2,6,10]
</pre>
  </div>
  <div>
   <h1 class="question_title">
    446. 等差数列划分 II - 子序列
   </h1>
   <p>
    如果一个数列至少有三个元素，并且任意两个相邻元素之差相同，则称该数列为等差数列。
   </p>
   <p>
    例如，以下数列为等差数列:
   </p>
   <pre>1, 3, 5, 7, 9
7, 7, 7, 7
3, -1, -5, -9</pre>
   <p>
    以下数列不是等差数列。
   </p>
   <pre>1, 1, 2, 5, 7</pre>
   <p>
    &nbsp;
   </p>
   <p>
    数组 A 包含 N 个数，且索引从 0 开始。该数组
    <strong>
     子序列
    </strong>
    将划分为整数序列&nbsp;(P
    <sub>
     0
    </sub>
    , P
    <sub>
     1
    </sub>
    , ..., P
    <sub>
     k
    </sub>
    )，P 与 Q 是整数且满足 0 &le; P
    <sub>
     0
    </sub>
    &lt; P
    <sub>
     1
    </sub>
    &lt; ... &lt; P
    <sub>
     k
    </sub>
    &lt; N。
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    如果序列 A[P
    <sub>
     0
    </sub>
    ]，A[P
    <sub>
     1
    </sub>
    ]，...，A[P
    <sub>
     k-1
    </sub>
    ]，A[P
    <sub>
     k
    </sub>
    ] 是等差的，那么数组 A 的
    <strong>
     子序列
    </strong>
    (P0，P1，&hellip;，PK) 称为等差序列。值得注意的是，这意味着 k &ge; 2。
   </p>
   <p>
    函数要返回数组 A 中所有等差子序列的个数。
   </p>
   <p>
    输入包含 N 个整数。每个整数都在 -2
    <sup>
     31
    </sup>
    和 2
    <sup>
     31
    </sup>
    -1 之间，另外 0 &le; N &le; 1000。保证输出小于 2
    <sup>
     31
    </sup>
    -1。
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     示例：
    </strong>
   </p>
   <p>
    &nbsp;
   </p>
   <pre><strong>输入：</strong>[2, 4, 6, 8, 10]

<strong>输出：</strong>7

<strong>解释：</strong>
所有的等差子序列为：
[2,4,6]
[4,6,8]
[6,8,10]
[2,4,6,8]
[4,6,8,10]
[2,4,6,8,10]
[2,6,10]
</pre>
   <p>
    &nbsp;
   </p>
  </div>
 </body>
</html>